package com.webauto.test_case;

import java.util.Map;
import java.util.Set;

import org.openqa.selenium.By;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.alibaba.fastjson.JSON;
import com.webauto.asserts.assertUtil;
import com.webauto.data_driver.CaseUtil;
import com.webauto.data_driver.ExcelUtil;
import com.webauto.po.PO;
import com.webauto.pojo.Case;
import com.webauto.selenium.SeleniumDriverUtil;
import com.webauto.selenium.UseElementUtil;

public class Test2_ClientManager_Search extends BaseCase {
	/**
	 * PS:测试方法
	 * 
	 * @param testNum        测试编号
	 * @param caseNum        用例编号
	 * @param caseName       测试名称
	 * @param caseType       测试类型
	 * @param testData       测试数据
	 * @param expectedResult 预计结果
	 * @param actualResult   实际结果
	 */
	@Test(dataProvider = "datas")
	public void clientManager_Search(String testNum, String caseNum, String caseName, String caseType, String testData,String checkPoint,
			String expectedResult, String actualResult) {
		PO navigation = new PO("导航栏");
		navigation.click("客户管理");
		navigation.click("子集客户管理");
		PO clientManager = new PO("客户管理", testData);
		clientManager.switchToFrame("客户管理iframe");
		clientManager.selectByVisibleText("搜索条件", "选项");
		clientManager.sendKeys("搜索框", "搜索关键字");
		clientManager.click("搜索按钮");
		// 断言结果
		boolean flag = false;
		String result = null;
		try {
			if ("1".equals(caseType)) {
				// 获取检查点选择器对象
				By checkPointBy = clientManager.getByByCheckPoint(checkPoint);
				// 获取检查元素的文本
				result = UseElementUtil.getText(checkPointBy);
				// 断言
				flag = assertUtil.check(result, expectedResult);
			} else if ("0".equals(caseType)) {
				// 获取检查点选择器对象
				By checkPointBy = clientManager.getByByCheckPoint(checkPoint);
				// 获取检查元素的文本
				result = UseElementUtil.getText(checkPointBy);
				// 断言
				flag = assertUtil.equals(result, expectedResult);
			} else {
				throw new AssertionError("+++测试类型不存在,测试类型:[" + caseType + "]+++");
			}
		} catch (AssertionError e) {
			throw new AssertionError("+++用例" + caseNum + "执行未通过," + e.getMessage() + "+++");
		} finally {
			CaseUtil.writeData(flag, "用例", caseNum, "ActualResult", result);
		}
	}

	/**
	 * PS:数据提供者
	 * 
	 * @return 数据二维数组,Test方法会按照数组数量进行多次测试
	 */
	@DataProvider(name = "datas")
	public Object[][] datas() {
		Object[][] datas = CaseUtil.getExcelEntity("testNum", "test-002", ExcelUtil.cases, ExcelUtil.casefields,
				Case.class);
		return datas;
	}

	@BeforeMethod
	public void beforeClass() {

	}
}
